package ldh.serialize.type;

import java.io.IOException;

import ldh.serialize.BinarySerialized;
import ldh.serialize.io.ByteBuf;
import ldh.serialize.util.SerializedUtil;

public class DoubleSerialized implements BinarySerialized<Double> {

	@Override
	public void write(ByteBuf out, Double d) throws IOException {
		Long data = null;
		if (d != null) {
			data = Double.doubleToLongBits(d);
		}
		SerializedUtil.writeLong(out, data);
	}

	@Override
	public Double read(ByteBuf in) throws IOException {
		Long data = SerializedUtil.readLong(in);
		if (data == null) {
			return null;
		}
		return Double.longBitsToDouble(data);
	}

	@Override
	public Class<Double> getClassType() {
		return Double.class;
	}
}
